package com.example.demo.servlet;

import com.example.demo.dao.UserDao;
import com.example.demo.entity.UserVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/updateuser")
public class UpdateUserServlet extends HttpServlet {

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UserVo user=new UserVo();
        String name = req.getParameter("Username");
        int id = Integer.parseInt(req.getParameter("UserID"));
        String password=req.getParameter("Password");
        String telephone=req.getParameter("Telephone");
        String gender=req.getParameter("Gender");
        user.setGender(gender);
        user.setTelephone(telephone);
        user.setUserName(name);
        user.setUserID(id);
        user.setPassword(password);

        try {
            new UserDao().updateUser(user);
            req.getRequestDispatcher("/category/list").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }

    }
}
